package com.pro.service.imple;

import com.pro.dao.UserCouponMapper;
import com.pro.entity.UserCoupon;
import com.pro.service.UserCouponService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName: UserCouponServiceImple
 * @Author: 笑笑
 * @DATE: 2021/11/18
 * @TIME: 下午 08:47
 */
@Service
public class UserCouponServiceImple implements UserCouponService {
    @Autowired
    private UserCouponMapper userCouponMapper;

    //查询所有优惠券信息--表
    @Override
    public List<UserCoupon> getAllTable(UserCoupon userCoupon) {
        return userCouponMapper.getAllTable(userCoupon);
    }

    //根据id查看优惠券
    @Override
    public UserCoupon getById(Integer couponId) throws Exception {
        if (couponId == null || couponId < 1){
            throw new Exception("id有误");
        }
        return userCouponMapper.getById(couponId);
    }

    //根据id删除优惠券
    @Override
    public Boolean deleteUserCoupon(Integer couponId) throws Exception {
        if (couponId == null || couponId < 1){
            throw new Exception("id有误");
        }
        return userCouponMapper.deleteUserCoupon(couponId);
    }

    //添加优惠券
    @Override
    public Boolean addUserCoupon(UserCoupon userCoupon) {
        userCoupon.setCreateDate(new Date());
        userCoupon.setType(2);
        return userCouponMapper.addUserCoupon(userCoupon);
    }

    //根据id修改优惠券
    @Override
    public Boolean updateUserCoupon(UserCoupon userCoupon) throws Exception {
        if (userCoupon.getCouponId() == null || userCoupon.getCouponId() < 1){
            throw new Exception("id不正确");
        }
        userCoupon.setUpdateDate(new Date());
        return userCouponMapper.updateUserCoupon(userCoupon);
    }
}
